package com.xxxx.server.controller;


import com.xxxx.server.pojo.Salary;
import com.xxxx.server.service.ISalaryService;
import com.xxxx.server.vo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 学海无涯
 * @since 2021-11-15
 */
@RestController
@RequestMapping("/salary/sob")
@Api(tags = "工资账套管理")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @ApiOperation("获取所有工资账套")
    @GetMapping("")
    public RespBean<List<Salary>> getAllSalaries(){
        List<Salary> list = salaryService.list();
        return new RespBean<List<Salary>>().success("ok",list);
    }

    @ApiOperation("添加工资账套")
    @PostMapping("")
    public RespBean addSalary(@RequestBody Salary salary){
        if (salaryService.save(salary)){
            return new RespBean().success("添加成功");
        }
        return new RespBean().error("添加失败");
    }

    @ApiOperation("删除工资账套")
    @DeleteMapping("/{id}")
    public RespBean delSalary(@PathVariable Integer id){
        if (salaryService.removeById(id)){
            return new RespBean().success("删除成功");
        }
        return new RespBean().error("删除失败");
    }

    @ApiOperation("修改工资账套")
    @PutMapping("")
    public RespBean editSalary(@RequestBody Salary salary){
        if (salaryService.updateById(salary)){
            return new RespBean().success("修改成功");
        }
        return new RespBean().error("修改失败");
    }
}
